package com.tuyan.aixiang.component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.tuyan.aixiang.R;
import com.tuyan.aixiang.common.lang.VoidFunction;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StartPage extends RelativeLayout {

    @BindView(R.id.iv_title)
    ImageView ivTitle;

    @BindView(R.id.iv_main)
    ImageView ivMain;

    @BindView(R.id.iv_indicator)
    ImageView ivIndicator;

    @BindView(R.id.iv_start)
    ImageView ivStart;

    public StartPage(Context context) {
        this(context, null);
    }

    public StartPage(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StartPage(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View contentView = LayoutInflater.from(context).inflate(R.layout.page_start, this);
        ButterKnife.bind(contentView, this);
    }

    public void setup(int title, int main, int indicator) {
        Glide.with(getContext()).load(title).into(ivTitle);
        Glide.with(getContext()).load(main).into(ivMain);
        Glide.with(getContext()).load(indicator).into(ivIndicator);
//
//        ImageUtil.loadBitmapDrawable(getContext(), ivTitle, title);
//        ImageUtil.loadBitmapDrawable(getContext(), ivMain, main);
//        ImageUtil.loadBitmapDrawable(getContext(), ivIndicator, indicator);

//        ivTitle.setImageResource(title);
//        ivMain.setImageResource(main);
//        ivIndicator.setImageResource(indicator);

        ivIndicator.setVisibility(VISIBLE);
    }


    public void setStartCallback(VoidFunction func) {
        ivStart.setVisibility(VISIBLE);

        ivStart.setOnClickListener(v -> {
            func.call();
        });
    }
}
